// 静态方法的添加
const mongoose = require('mongoose');
async function main(){
    await mongoose.connect('mongodb://localhost:27017/local')
    const SchemaIndex = new mongoose.Schema({
        name:String,
        rote:String,
        isbn:String,
    }) 

    SchemaIndex.static('findByIsbn',function(isbn,cb){
        this.find({isbn:isbn}).then(res=>{
            cb(res)
        })
    })

    SchemaIndex.methods.print=function(){
        console.log(this.name)
        console.log('\n',this.rote)
    }
    let index = mongoose.model('index',SchemaIndex)
    let indexData = new index({name:'index',rote:'/index',isbn:3434})
    indexData.save().then(async res=>{
        await index.findByIsbn('3434',function(res){console.log('find success:',res)})
        indexData.print()
    })

    
}

main()